package day12_thread_code.com.itheima.d2_thread_api;

public class Demo1_Thread {
    public static void main(String[] args) {
        MyThread t1 = new MyThread("线程1");
        t1.start();
        System.out.println("t1.getName() = " + t1.getName());

        MyThread t2 = new MyThread("线程2");
        t2.start();
        System.out.println("t2.getName() = " + t2.getName());
        Thread m = Thread.currentThread();
        m.setName("主线程");
        System.out.println("m.getName() = " + m.getName());

        for (int i = 0; i < 4; i++) {
            System.out.println(m.getName() + ": " + i);
        }
    }
}
class MyThread extends Thread{
    public MyThread(String name) {
        super(name);
    }
    @Override
    public void run() {
        for (int i = 0; i < 4; i++) {
            System.out.println(Thread.currentThread().getName() + "输出：" + i);
        }
    }
}
